/* This is the header file, the only things that might need to be changed are:
 * PPM_DEFAULT_CHANNELS - This is the number of channels that you want to have on the drone
 * PPM_PULSE_LENGTH_uS - This is the length of the pulse, you might have to play around with the variable find the correct value
 * PPM_FRAME_LENGTH_uS - This is the length of the separation pause. The larger the value, the more stable the readings and the higher the latency, but
 *                       the lower the value, the less stable the readings and a lower latency. Try play around with this value until you find your sweet spot.
 */
#ifndef _PPMEncoder_h_
#define _PPMEncoder_h_

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#define PPM_DEFAULT_CHANNELS 8

#define PPM_PULSE_LENGTH_uS 25
#define PPM_FRAME_LENGTH_uS 40000

class PPMEncoder {

  private:
    int16_t channels[10];
    int16_t err;
    uint16_t elapsedUs;

    uint8_t numChannels;
    uint8_t currentChannel;
    byte outputPin;
    boolean state;
  
    uint8_t onState;
    uint8_t offState;


  public:
    static const uint16_t MIN = 1000;
    static const uint16_t MAX = 2000;

    void setChannel(uint8_t channel, uint16_t value);
    void setChannelPercent(uint8_t channel, uint8_t percent);

    void begin(uint8_t pin);
    void begin(uint8_t pin, uint8_t ch);
    void begin(uint8_t pin, uint8_t ch, boolean inverted);

    void interrupt();
};

extern PPMEncoder ppmEncoder;

#endif
